package nl.hu.verbrandendephoenix.client;

import nl.hu.verbrandendephoenix.controller.Login;

import com.google.gwt.user.client.ui.RootPanel;

public class AppManager {

	private static AppManager appManager;
	private RootPanel pnlContent;
	private ServerServiceAsync rpcService;
	private MenuManager menuManager;
	private HistoryListener hL;
	
	private AppManager(ServerServiceAsync rpcService) {
		this.rpcService = rpcService;
		this.pnlContent = RootPanel.get("content");
	}
	/**
	 * Ophalen instantie AppManager (dit om te voorkomen dat hij meer dan een keer wordt aangemaakt
	 * @return AppManager appManager de klasse zelf.
	 */
	public static AppManager get() {
		return appManager;
	}
	public static AppManager create(ServerServiceAsync rpcService) {
		if(appManager == null) {
			appManager = new AppManager(rpcService);
			appManager.initiate();
		}
		return appManager;
	}
	private void initiate() {
		createLogin();
		this.menuManager = new MenuManager();
		this.hL = new HistoryListener(pnlContent);
	}
	/**
	 * Maak login veld aan onder het menu
	 */
	private void createLogin() {
		new Login(RootPanel.get("login"));
	}
	/**
	 * Het panel waar alle pagina's in worden gestopt
	 * @return Panel pnlContent het content panel.
	 */
	public RootPanel getContentPanel() {
		return pnlContent;
	}
	
	public ServerServiceAsync getRpcService() {
		return rpcService;
	}
	
	public MenuManager getMenuManager() {
		return menuManager;
	}
	
	public HistoryListener getHistoryListener() {
		return hL;
	}
	
}
